package editor.ui
{
	import com.bit101.components.CheckBox;
	import com.bit101.components.Label;
	import com.bit101.components.PushButton;
	import com.bit101.components.RadioButton;
	import com.bit101.components.Text;
	import com.bit101.components.Window;
	
	import editor.manager.MapManger;
	import editor.map.TileLayer;
	import editor.map.minimap.Minimap;
	
	import flash.display.BitmapData;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filesystem.File;
	import flash.net.FileFilter;
	import flash.utils.ByteArray;
	
	public class LayerControllerWindow extends Window
	{
		
		private var _backgroundBtn:PushButton;
		private var _backArdsText:Text;
		private var _tileRadio:RadioButton;
		private var _maskRadio:RadioButton;
		private var _backRadio:RadioButton;
		private var _labelA:Label;
		private var _maskCheckBox:CheckBox;
		private var _tileCheckBox:CheckBox;
		private var _backCheckBox:CheckBox;
		private var _labelB:Label;
		private var _minimap:Minimap;
		private var _xyLabel:Label;
		
		public function LayerControllerWindow(parent:DisplayObjectContainer, xpos:Number = 0, ypos:Number = 0)
		{
			super(parent, xpos, ypos, "小地图");
			setSize(120, 150);
			
			_backgroundBtn 	= new PushButton(this, 10, 65, "添加背景图", clickAddBack);
			_xyLabel 		= new Label(this, 130, 65); 
//			_tileRadio = new RadioButton(this, 20, 150, "Tile Layer");
//			
//			_maskRadio = new RadioButton(this, 20, 130, "Mask Layer");
//			
//			_backRadio = new RadioButton(this, 20, 170, "Background Layer");
//			
//			_labelA = new Label(this, 10, 105, "Select a Layer:");
//			
//			_maskCheckBox = new CheckBox(this, 20, 225, "Mask Layer");
//			
//			_tileCheckBox = new CheckBox(this, 20, 245, "Tile Layer");
//			_tileCheckBox.selected = true;
//			
//			_backCheckBox = new CheckBox(this, 20, 265, "Background Layer");
//			_backCheckBox.selected = true;
//			
//			_labelB = new Label(this, 10, 200, "Hide Or Show:");
			
			
		}
		
		/**
		 * 更新坐标信息
		 * @param x
		 * @param y 
		 */		
		public function updateXY(x:int, y:int):void
		{
			_xyLabel.text = "x: " + x + "   y:" + y;
		}
		
		public function addMinimap():void
		{
			_minimap = new Minimap();
			_minimap.x = 10;
			_minimap.y = 10;
			addChild(_minimap);
			_backgroundBtn.y 	= TileLayer.MAP_LOGIC_HEIGHT + 20;
			_xyLabel.y			= TileLayer.MAP_LOGIC_HEIGHT + 20;
			this.setSize(TileLayer.MAP_LOGIC_WIDTH + 20, TileLayer.MAP_LOGIC_HEIGHT + 70);
		}
		
		//点击增加背景按钮
		private function clickAddBack(evt:MouseEvent):void
		{
			var file:File = new File();
			file.addEventListener(Event.SELECT, ok);
			file.browseForOpen("打开背景图", [new FileFilter("*.jpg;*.jpeg;*.png", "*.jpg;*.jpeg;*.png")]);
		}
		
		//文件选择完成
		private function ok(evt:Event):void
		{
			var file:File = evt.target as File;
			MapManger.getInstance().updateBackgroundImage(file);
		}
		
		//
	}
}